package com.maxt;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.XmlWebApplicationContext;

/**
 * 
* @ClassName: StartupListener
* @Package: com.maxt
* @Description: 容器初始化完成后执行
* @author: maxt
* @date 2017年7月13日 下午4:17:25
*
 */
@Service
public class StartupListener implements ApplicationListener<ContextRefreshedEvent> {

	@Override
	public void onApplicationEvent(ContextRefreshedEvent applicationEvent) {
		
		String applicationEventName = applicationEvent.getApplicationContext().getDisplayName();
		System.out.println("applicationEventName---------------------->"+applicationEventName);
		
		//只在初始化“根上下文”的时候执行
        if (applicationEvent.getSource() instanceof XmlWebApplicationContext) {
            if (((XmlWebApplicationContext) applicationEvent.getSource()).getDisplayName().equals("Root WebApplicationContext")) {
            	System.out.println("<---------------------------XmlWebApplicationContext--------------------------->");
            }
        }
            
		
	}

}
